﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.IO;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
using System.ComponentModel;
using System.Drawing.Drawing2D;
using Village_Project.Core;

namespace Village_Project
{
    public partial class reg1 : System.Web.UI.Page
    {
     
        protected void Page_Load(object sender, EventArgs e)
        
        
        
        {

            

            string CIDstring = Request.QueryString["CID"];
          

            //ถ้ามีคิวรี่สติง ให้คิวรี่โชว์ตามคิวรี่
            if (CIDstring != null)
            {
                //reg.aspx?CID=1669800114444

                Session["CID"] = CIDstring;
                show_Images();
                show_Images2();
                show_Images3();
                
                RegShowPanel.Visible = true;
                CensusRegShowPanel.Visible = true;
                LiveRegShowPanel.Visible = true;
                loaddatareg();
                MainRegPanel.Visible = false;
                  CensusRegPanel.Visible=false;
                  LiveRegPanel.Visible=false;
                  Session["LastName"] = RLName.Text;
                  Session["FirstName"] = RFName.Text;

                  loaddatadropdownProvince();
                  loaddatadropdownProvince2();
                  loaddatadropdownTitles();
                  loaddataBloodTypeRBL();
                  loaddataForeignD();
                  loaddataGenderR();
            }

            else
            //ถ้า ไม่มีคิวรี่สติง( เข้าแค่ ChildDetails.aspx   ธรรมดา จะถือเอา sesson CID มาคิวรี่โชว์)  ทำเพื่อสำหรับหน้ากลับข้อมูลส่วนตัวจะได้กลับไปที่  ChildDetails.aspx ได้
            {
              //  reg.aspx

                if (!IsPostBack)
                {
                  
                    RegShowPanel.Visible = false;
                    CensusRegShowPanel.Visible = false;
                    LiveRegShowPanel.Visible = false;

                    MainRegPanel.Visible = true;
                    CensusRegPanel.Visible = true;
                    LiveRegPanel.Visible = true;
                    Panel1.Visible = false;
                    loaddatadropdownchildType();
                    checkinfo();
                    loaddatadropdownProvince();
                    loaddatadropdownProvince2();
                    loaddatadropdownTitles();
                    loaddataBloodTypeRBL();
                    loaddataForeignD();
                    loaddataGenderR();
             
                    checkinfo();
                }

            }
            
            
            
            
            
            
            
            
            
            
            
          



            //checkinfo();


        }
        //รูปด้านข้าง

        public void show_Images()
        {
            string sj = "";



            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);

            SqlCommand CmdSql2 = new SqlCommand("SELECT Child_Pic FROM [Person] where CID=@CID", conn);
            conn.Open();
            CmdSql2.Parameters.AddWithValue("@CID", Session["CID"]);

            SqlDataReader reader2 = CmdSql2.ExecuteReader();

            if (reader2.Read())
            {
                sj = reader2["Child_Pic"].ToString();
            }
            else
            {
                sj = "~/pic/profile/nopic.jpg";
            }
            conn.Close();
            reader2.Close();


            Image1.ImageUrl = (sj);
        }






        //รูปด้านล่าง

        public void show_Images2()
        {
            string sj = "";



            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);

            SqlCommand CmdSql2 = new SqlCommand("SELECT Child_Pic FROM [Person] where CID=@CID", conn);
            conn.Open();
            CmdSql2.Parameters.AddWithValue("@CID", Session["CID"]);

            SqlDataReader reader2 = CmdSql2.ExecuteReader();

            if (reader2.Read())
            {
                sj = reader2["Child_Pic"].ToString();
            }
            else
            {
                sj = "~/pic/profile/nopic.jpg";
            }
            conn.Close();
            reader2.Close();


            Image2.ImageUrl = (sj);
        }






        public void show_Images3()
        {
            string sj = "";



            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);

            SqlCommand CmdSql2 = new SqlCommand("SELECT Child_PicCID FROM [Person] where CID=@CID", conn);
            conn.Open();
            CmdSql2.Parameters.AddWithValue("@CID", Session["CID"]);

            SqlDataReader reader2 = CmdSql2.ExecuteReader();

            if (reader2.Read())
            {
                sj = reader2["Child_PicCID"].ToString();
            }
            else
            {
                sj = "~/pic/profile/nopic.jpg";
            }
            conn.Close();
            reader2.Close();


            Image3.ImageUrl = (sj);
        }


      

     





        protected void checkinfo()
        {
            //string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            //SqlConnection conn = new SqlConnection(constr);

            //SqlCommand CmdSql2 = new SqlCommand("SELECT CID FROM [Person] where CID=@CID", conn);
            //conn.Open();
            //CmdSql2.Parameters.AddWithValue("@CID", Session["CID"]);

            //SqlDataReader reader2 = CmdSql2.ExecuteReader();


            if (Session["CID"] == null)
            {

                edit_info.Visible = false;
                reg_button.Visible = true;
                Panel1.Visible = false;
            }

            else

            {

            



                loaddataregtb();
                edit_info.Visible = true;
                reg_button.Visible = false;
                CID.ReadOnly = true;
                show_Images();
                show_Images2();
                show_Images3();
               
             
            }

        }




        protected void Wizard1_PreRender(object sender, EventArgs e)
        {
            //Repeater SideBarList = Wizard1.FindControl("HeaderContainer").FindControl("SideBarList") as Repeater;
            //SideBarList.DataSource = Wizard1.WizardSteps;
            //SideBarList.DataBind();
        }

        //protected string GetClassForWizardStep(object wizardStep)
        //{
        //    //WizardStep step = wizardStep as WizardStep;

        //    //if (step == null)
        //    //{
        //    //    return "";
        //    //}
        //    //int stepIndex = Wizard1.WizardSteps.IndexOf(step);

        //    //if (stepIndex < Wizard1.ActiveStepIndex)
        //    //{
        //    //    return "prevStep";
        //    //}
        //    //else if (stepIndex > Wizard1.ActiveStepIndex)
        //    //{
        //    //    return "nextStep";
        //    //}
        //    //else
        //    //{
        //    //    return "currentStep";
        //    //}
        //}

        protected void AddressHomeCheckbox_CheckedChanged(object sender, EventArgs e)
        {
        }


        //Wizard1_ActiveStepChanged
        protected void Wizard1_ActiveStepChanged(object sender, EventArgs e)
        {
            //int step = Wizard1.ActiveStepIndex;
            //if (step == 1)
            //{
            //    //Insert Student Profile Data

            //}
            //else if (step == 2)
            //{

            //}
            //else if (step == 3)
            //{

            //}
            //else
            //{

            //}
        }

        //=================================================================================
        //Dropdown Bind Function
        private void BindIntroDropdownList()
        {
          
        }

        //Bind Relation DropdownList

        private void BindRelationDropdownList()
        {
        
        }

        protected void BDIB_Click(object sender, ImageClickEventArgs e)
        {
            BDCal.Visible = true;
        }

        protected void CMIDIB_Click(object sender, ImageClickEventArgs e)
        {
            CMIDCal.Visible = true;
        }

        protected void CMODIB_Click(object sender, ImageClickEventArgs e)
        {
            CMODCal.Visible = true;
        }

        protected void LMIDIB_Click(object sender, ImageClickEventArgs e)
        {
            LMIDCal.Visible = true;
        }

        protected void LMODIB_Click(object sender, ImageClickEventArgs e)
        {
            LMODCal.Visible = true;
        }

        protected void LMIDCal_SelectionChanged(object sender, EventArgs e)
        {
            LMIDTB.Text = LMIDCal.SelectedDate.ToShortDateString();
            LMIDCal.Visible = false;
        }

        protected void BDCal_SelectionChanged(object sender, EventArgs e)
        {
          birthday.Text = BDCal.SelectedDate.ToShortDateString();
            BDCal.Visible = false;
        }

        protected void CMIDCal_SelectionChanged(object sender, EventArgs e)
        {
            CMIDTB.Text = CMIDCal.SelectedDate.ToShortDateString();
          CMIDCal.Visible = false;
        }

        protected void CMODCal_SelectionChanged(object sender, EventArgs e)
        {
            CMODTB.Text = CMODCal.SelectedDate.ToShortDateString();
            CMODCal.Visible = false;
        }

        protected void LMODCal_SelectionChanged(object sender, EventArgs e)
        {
            LMODTB.Text = LMODCal.SelectedDate.ToShortDateString();
           LMODCal.Visible = false;
        }

        protected void CID_TextChanged(object sender, EventArgs e)
        {

        }

        protected void EditReg_Button_Click(object sender, EventArgs e)
        {
            
            Response.Redirect("reg.aspx");
        }

        protected void reg_button_Click(object sender, EventArgs e)
        {
            insert();
            sessionsend();



            String a;

            //  ('reg.aspx?CID=('1669800114444')')

            //(reg.aspx?CID=(1669800114444)')
            a = "reg.aspx?CID=" + Session["CID"] + "";
            Response.Redirect("" + a + "");

        }





        protected void sessionsend()
        {
            Session["LastName"] = LastName.Text;
            Session["FirstName"] = FirstName.Text;
            Session["CID"] = CID.Text;
            String CIDLabel = (string)Session["CID"];
            CIDlabel.Text = CIDLabel;

        }
        protected void insert()
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn2 = new SqlConnection(constr);
            SqlCommand CmdSql2 = new SqlCommand("INSERT INTO [Person] (CID,FirstName,LastName,title) VALUES (@CID,@FirstName,@LastName,@DisabilityType)", conn2);
            conn2.Open();
            CmdSql2.Parameters.AddWithValue("@CID", CID.Text);
            CmdSql2.Parameters.AddWithValue("@LastName", LastName.Text);
            CmdSql2.Parameters.AddWithValue("@FirstName", FirstName.Text);
            CmdSql2.Parameters.AddWithValue("@DisabilityType", DisabilityType.SelectedValue);
            CmdSql2.ExecuteNonQuery();
            conn2.Close();


            sessionsend();


            SqlCommand CmdSqledu = new SqlCommand("INSERT INTO [EducationChild] (CID) VALUES (@CID)", conn2);
            conn2.Open();
            CmdSqledu.Parameters.AddWithValue("@CID", CID.Text);

            CmdSqledu.ExecuteNonQuery();
            conn2.Close();

            SqlCommand rightsinfo = new SqlCommand("INSERT INTO [ExistingWelfare] (CID) VALUES (@CID)", conn2);
            conn2.Open();
            rightsinfo.Parameters.AddWithValue("@CID", CID.Text);

            rightsinfo.ExecuteNonQuery();
            conn2.Close();



            //Session["LastName"] = LastName;
            //Session["FirstName"] = FirstName;  
            //Session["CID"] = CID;
            SqlCommand CmdSql = new SqlCommand("UPDATE [Person] SET Title=@Title,DOB=@DOB,Gender=@Gender,BloodType=@BloodType,Nation=@Nation,Race=@Race,Religion=@Religion,Foreigner=@Foreigner,LiveHomeStatus=@LiveHomeStatus,LiveHouseNumber=@LiveHouseNumber,LiveMooNumber=@LiveMooNumber,LiveVillageName=@LiveVillageName,LiveAlley=@LiveAlley,LiveStreetName=@LiveStreetName,LiveTumbon=@LiveTumbon,LiveCity=@LiveCity,LiveProvince=@LiveProvince,LivePostCode=@LivePostCode,LiveMoveInDate=@LiveMoveInDate,LiveMoveOutDate=@LiveMoveOutDate,LiveMoveOutReason=@LiveMoveOutReason,CensusHouseNumber=@CensusHouseNumber,CensusMooNumber=@CensusMooNumber,CensusVillageName=@CensusVillageName,CensusAlley=@CensusAlley,CensusStreetName=@CensusStreetName,CensusTumbon=@CensusTumbon,CensusCity=@CensusCity,CensusProvince=@CensusProvince,CensusPostCode=@CensusPostCode,CensusMoveInDate=@CensusMoveInDate,CensusMoveOutDate=@CensusMoveOutDate,CensusMoveOutReason=@CensusMoveOutReason,HomePhone=@HomePhone,Mobile=@Mobile,RecordedStaffID=@RecordedStaffID,DateTimeUpdate=@DateTimeUpdate WHERE CID=@CID", conn2);
            conn2.Open();

            CmdSql.Parameters.AddWithValue("@Title", TitlesD.SelectedValue);
          CmdSql.Parameters.AddWithValue("@Gender", GenderR.SelectedValue);
            CmdSql.Parameters.AddWithValue("@BloodType", BloodTypeRBL.SelectedValue);
            CmdSql.Parameters.AddWithValue("@DOB", birthday.Text);
            CmdSql.Parameters.AddWithValue("@CID", Session["CID"]);
            CmdSql.Parameters.AddWithValue("@Nation", NationTB.Text);
            CmdSql.Parameters.AddWithValue("@Race", RaceTB.Text);
            CmdSql.Parameters.AddWithValue("@Religion", RaceTB.Text);
            CmdSql.Parameters.AddWithValue("@Foreigner", ForeignD.SelectedValue);
        CmdSql.Parameters.AddWithValue("@LiveHomeStatus", LHomeTB.Text);
            //CmdSql.Parameters.AddWithValue("@EducationStatus", EducationStatus.SelectedValue);
            //บ้านเลขที่
            CmdSql.Parameters.AddWithValue("@LiveHouseNumber", LHomeTB.Text);
            //ชื่อถนน
            CmdSql.Parameters.AddWithValue("@LiveStreetName", LStreetTB.Text);
            CmdSql.Parameters.AddWithValue("@LiveTumbon", LTambonD.SelectedValue);
            CmdSql.Parameters.AddWithValue("@LiveCity", LCityD.SelectedValue);
            CmdSql.Parameters.AddWithValue("@LiveProvince", LProvinceD.SelectedValue);
            CmdSql.Parameters.AddWithValue("@LivePostCode", LPostcodeTB.Text);

            CmdSql.Parameters.AddWithValue("@CensusHouseNumber", CHomeTB.Text);
            CmdSql.Parameters.AddWithValue("@CensusStreetName", CStreetTB.Text);
            CmdSql.Parameters.AddWithValue("@Censustumbon", CTambonD.SelectedValue);
            CmdSql.Parameters.AddWithValue("@CensusCity", CCityD.SelectedValue);
            CmdSql.Parameters.AddWithValue("@CensusProvince", CProvinceD.SelectedValue);
            CmdSql.Parameters.AddWithValue("@CensusPostCode", CPostcodeTB.Text);
            CmdSql.Parameters.AddWithValue("@HomePhone", CTelTB.Text);
            CmdSql.Parameters.AddWithValue("@Mobile", CCellphoneTB.Text);
            CmdSql.Parameters.AddWithValue("@RecordedStaffID", RecordedStaffID.Text);
            CmdSql.Parameters.AddWithValue("@DateTimeUpdate", DateTime.Now);

            CmdSql.Parameters.AddWithValue("@LiveMoveInDate", LMIDTB.Text);
            CmdSql.Parameters.AddWithValue("@LiveMoveOutReason", LiveMoveOutReason.SelectedValue);
            CmdSql.Parameters.AddWithValue("@CensusMoveOutReason", CensusMoveOutReason.SelectedValue);
            CmdSql.Parameters.AddWithValue("@LiveMoveOutDate", LMODTB.Text);


            CmdSql.Parameters.AddWithValue("@CensusMoveOutDate", CMODTB.Text);
            CmdSql.Parameters.AddWithValue("@CensusMoveInDate", CMIDTB.Text);

            CmdSql.Parameters.AddWithValue("@CensusMooNumber", CGroupTB.Text);
            CmdSql.Parameters.AddWithValue("@CensusVillageName", CHomeNTB.Text);
            CmdSql.Parameters.AddWithValue("@CensusAlley", CSoyTB.Text);

            CmdSql.Parameters.AddWithValue("@LiveMooNumber", LGroupTB.Text);
            CmdSql.Parameters.AddWithValue("@LiveVillageName", LHomeNTB.Text);
            CmdSql.Parameters.AddWithValue("@LiveAlley", LSoyTB.Text);
         
            CmdSql.ExecuteNonQuery();
            conn2.Close();
            //MessageBox("ลงทะเบียนเรียบร้อยครับ");
        }











        //ดึงข้อมูลมาโชว์หน้า reg.aspx



        protected void loaddatareg()
        {








            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);


            SqlCommand CmdSql2 = new SqlCommand("SELECT CID,Title,FirstName,LastName,DOB,Gender,BloodType,Nation,Race,Religion,title,Foreigner,LiveHomeStatus,LiveHouseNumber,LiveMooNumber,LiveVillageName,LiveAlley,LiveStreetName,LiveTumbon,LiveCity,LiveProvince,LivePostCode,LiveMoveInDate,LiveMoveOutDate,LiveMoveOutReason,CensusHouseNumber,CensusMooNumber,CensusVillageName,CensusAlley,CensusStreetName,CensusTumbon,CensusCity,CensusProvince,CensusPostCode,CensusMoveInDate,CensusMoveOutDate,CensusMoveOutReason,HomePhone,Mobile,RecordedStaffID,DateTimeUpdate FROM [Person] where CID=@CID", conn);
            conn.Open();
            CmdSql2.Parameters.AddWithValue("@CID", Session["CID"]);

            SqlDataReader reader2 = CmdSql2.ExecuteReader();

            //CmdSql.Parameters.AddWithValue("@Gender", RadioButtonList1.SelectedValue);
            // CmdSql.Parameters.AddWithValue("@BloodType", RadioButtonList2.SelectedValue);

         
        


            // CensusCity,CensusProvince,CensusPostcode,HomePhone,Mobile,RecordedStaffID
            if (reader2.Read())
            {
                //Gender.SelectedValue = reader2["Gender"].ToString();
               BloodTypeLB.Text = reader2["BloodType"].ToString();
                RFName.Text = reader2["FirstName"].ToString();
                RLName.Text = reader2["LastName"].ToString();
               

                RCIDLBL.Text = reader2["CID"].ToString();
            DBOLB.Text = reader2["DOB"].ToString();
                NationLB.Text = reader2["Nation"].ToString();
                RaceLB.Text = reader2["Race"].ToString();
                ReligionLB.Text = reader2["Religion"].ToString();

                ForeignerLB.Text = reader2["Foreigner"].ToString();
                LHomeLB.Text = reader2["LiveHouseNumber"].ToString();
                LStreetLB.Text = reader2["LiveStreetName"].ToString();
                LTambonLB.Text = reader2["LiveTumbon"].ToString();
               //LCityLB.Text = reader2["LiveCity"].ToString();
               //LProvinceLB.Text = reader2["LiveProvince"].ToString();
                LPostcodeLB.Text = reader2["LivePostCode"].ToString();
                CHomeLB.Text = reader2["CensusHouseNumber"].ToString();
                CStreetLB.Text = reader2["CensusStreetName"].ToString();
                CTambonLB.Text = reader2["Censustumbon"].ToString();
                //CCityLB.Text = reader2["CensusCity"].ToString();
                joinLiveProvince();
                joinCensusProvince();
                joinCensusCity();
                joinLiveCity();
                //CProvinceLB.Text = reader2["CensusProvince"].ToString();
                CPostcodeLB.Text = reader2["CensusPostCode"].ToString();
                CTelLB.Text = reader2["HomePhone"].ToString();
                CCellphoneLB.Text = reader2["Mobile"].ToString();
                //RecordedStaffID.Text = reader2["RecordedStaffID"].ToString();
                
                ////LiveMoveInDate,LiveMoveOutDate,CensusMoveInDate,CensusMoveOutDate  LiveMoveOutReason,CensusMoveOutReason
                LMORLB.Text = reader2["LiveMoveOutReason"].ToString();
                CMORLB.Text = reader2["CensusMoveOutReason"].ToString();
                LMIDLB.Text = reader2["LiveMoveInDate"].ToString();
                LMODLB.Text = reader2["LiveMoveOutDate"].ToString();
                CMIDLB.Text= reader2["CensusMoveInDate"].ToString();
                CMOBLB.Text = reader2["CensusMoveOutDate"].ToString();



                CGroupLB.Text = reader2["CensusMooNumber"].ToString();
                CVillageLB.Text = reader2["CensusVillageName"].ToString();
                CSoyLB.Text = reader2["CensusAlley"].ToString();
                LGroupLB.Text = reader2["LiveMooNumber"].ToString();
                LVillageLB.Text = reader2["LiveVillageName"].ToString();
                LSoyLB.Text = reader2["LiveAlley"].ToString();
               


                //EducationStatus.Text = reader2["EducationStatus"].ToString();
                //LiveHomeStatus.Text = reader2["LiveHomeStatus"].ToString();
                //DropDownList1.Text = reader2["Title"].ToString();




              
                //CmdSql.Parameters.AddWithValue("@CensusHouseMoo", CGroupTB.Text);
                //CmdSql.Parameters.AddWithValue("@CensusHouseName", CHomeNTB.Text);
                //CmdSql.Parameters.AddWithValue("@CensusHousesoy", CSoyTB.Text);
                //CmdSql.Parameters.AddWithValue("@LiveHouseMoo", LGroupTB.Text);
                //CmdSql.Parameters.AddWithValue("@LiveHouseName", LHomeNTB.Text);



               

                //   RadioButtonList1.Text = reader2["FMstatust"].ToString();
                //     RadioButton1.Text = reader2["FMstatust"].ToString();
            }
            else
            {
                //MessageBox("ไม่พบเลขบัตรครับ");
            }
            conn.Close();
            reader2.Close();








        }













        protected void loaddataregtb()
        {

            //loaddatadropdownCityall();
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);


            SqlCommand CmdSql2 = new SqlCommand("SELECT CID,Title,FirstName,LastName,DOB,Gender,BloodType,Nation,Race,Religion,title,Foreigner,LiveHomeStatus,LiveHouseNumber,LiveMooNumber,LiveVillageName,LiveAlley,LiveStreetName,LiveTumbon,LiveCity,LiveProvince,LivePostCode,LiveMoveInDate,LiveMoveOutDate,LiveMoveOutReason,CensusHouseNumber,CensusMooNumber,CensusVillageName,CensusAlley,CensusStreetName,CensusTumbon,CensusCity,CensusProvince,CensusPostCode,CensusMoveInDate,CensusMoveOutDate,CensusMoveOutReason,HomePhone,Mobile,RecordedStaffID,DateTimeUpdate FROM [Person] where CID=@CID", conn);
            conn.Open();
            CmdSql2.Parameters.AddWithValue("@CID", Session["CID"]);

            SqlDataReader reader2 = CmdSql2.ExecuteReader();

            //CmdSql.Parameters.AddWithValue("@Gender", RadioButtonList1.SelectedValue);
            // CmdSql.Parameters.AddWithValue("@BloodType", RadioButtonList2.SelectedValue);





            // CensusCity,CensusProvince,CensusPostcode,HomePhone,Mobile,RecordedStaffID
            if (reader2.Read())
            {
                CID.Text = reader2["CID"].ToString();
                GenderR.SelectedValue = reader2["Gender"].ToString();
                BloodTypeLB.Text = reader2["BloodType"].ToString();
                FirstName.Text = reader2["FirstName"].ToString();
                LastName.Text = reader2["LastName"].ToString();
                RCIDLBL.Text = reader2["CID"].ToString();
                birthday.Text = reader2["DOB"].ToString();
                NationTB.Text = reader2["Nation"].ToString();
                RaceTB.Text = reader2["Race"].ToString();
                ReligionTB.Text = reader2["Religion"].ToString();
                ForeignD.SelectedValue = reader2["Foreigner"].ToString();
                LHomeTB.Text = reader2["LiveHouseNumber"].ToString();
                LStreetTB.Text = reader2["LiveStreetName"].ToString();
                DisabilityType.SelectedValue = reader2["title"].ToString();
                
                LProvinceD.SelectedValue = reader2["LiveProvince"].ToString();
                loaddatadropdownLCity();
                LCityD.SelectedValue = reader2["LiveCity"].ToString();
                loaddatadropdownLTambon();
                LTambonD.SelectedValue = reader2["LiveTumbon"].ToString();



                LPostcodeTB.Text = reader2["LivePostCode"].ToString();
                CHomeTB.Text = reader2["CensusHouseNumber"].ToString();
                CStreetTB.Text = reader2["CensusStreetName"].ToString();


                
                //ต้องสร้าง dropdownlist ก่อนเรียกโหลดค่า
                CProvinceD.SelectedValue = reader2["CensusProvince"].ToString();
                loaddatadropdownCCity();
                CCityD.SelectedValue = reader2["CensusCity"].ToString();
                loaddatadropdownCTambon();
                CTambonD.SelectedValue = reader2["Censustumbon"].ToString();



                CPostcodeTB.Text = reader2["CensusPostcode"].ToString();
                CTelTB.Text = reader2["HomePhone"].ToString();
                CCellphoneTB.Text = reader2["Mobile"].ToString();
                //RecordedStaffID.Text = reader2["RecordedStaffID"].ToString();
               
                ////LiveMoveInDate,LiveMoveOutDate,CensusMoveInDate,CensusMoveOutDate  LiveMoveOutReason,CensusMoveOutReason
                LiveMoveOutReason.SelectedValue = reader2["LiveMoveOutReason"].ToString();
                CensusMoveOutReason.SelectedValue = reader2["CensusMoveOutReason"].ToString();
                
                LMIDTB.Text = reader2["LiveMoveInDate"].ToString();
                LMODTB.Text = reader2["LiveMoveOutDate"].ToString();
                CMIDTB.Text = reader2["CensusMoveInDate"].ToString();
                CMODTB.Text = reader2["CensusMoveOutDate"].ToString();



                //CGroupTB.Text = reader2["CensusHouseMoo"].ToString();
                ////CHomeNTB.Text = reader2["CensusHouseName"].ToString();
                ////CSoyTB.Text = reader2["CensusHousesoy"].ToString();
                //LGroupTB.Text = reader2["LiveHouseMoo"].ToString();
                ////LHomeNTB.Text =  reader2["LiveHouseName"].ToString();
                ////LHomeNLB.Text = reader2["LiveHousesoy"].ToString();



                //EducationStatus.Text = reader2["EducationStatus"].ToString();
                //LiveHomeStatus.Text = reader2["LiveHomeStatus"].ToString();
                //DropDownList1.Text = reader2["Title"].ToString();





                //CmdSql.Parameters.AddWithValue("@CensusHouseMoo", CGroupTB.Text);
                //CmdSql.Parameters.AddWithValue("@CensusHouseName", CHomeNTB.Text);
                //CmdSql.Parameters.AddWithValue("@CensusHousesoy", CSoyTB.Text);
                //CmdSql.Parameters.AddWithValue("@LiveHouseMoo", LGroupTB.Text);
                //CmdSql.Parameters.AddWithValue("@LiveHouseName", LHomeNTB.Text);






                //   RadioButtonList1.Text = reader2["FMstatust"].ToString();
                //     RadioButton1.Text = reader2["FMstatust"].ToString();
            }
            else
            {
                //MessageBox("ไม่พบเลขบัตรครับ");
            }
            conn.Close();
            reader2.Close();








        }

        protected void edit_info_Click(object sender, EventArgs e)
        {
            
            updatetb();

            String a;

            //  ('reg.aspx?CID=('1669800114444')')

            //(reg.aspx?CID=(1669800114444)')
            a = "reg.aspx?CID=" + Session["CID"] + "";
            Response.Redirect("" + a + "");
        }










        protected void ImageUpload_f()
        {

            // SqlConnection conn = new SqlConnection(strConnString);
            if (FileUpload1.HasFile)
            {
                //try
                string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
                SqlConnection conn = new SqlConnection(constr);









                //ไปใส่พาธไฟล์เอา

                string MapPath = ("~/pic/profile/");
                string filename = (string)Session["CID"];
                FileUpload1.SaveAs(Server.MapPath(MapPath) + filename + Path.GetExtension(FileUpload1.FileName));
                //FileUploader.SaveAs(filename + ".Jpeg");
                // string SQL = "INSERT INTO [ImageDek] ([Iddek],[FilePath]) VALUES (@Iddek,@Filepath)";
                //เพิ่มไฟล์ไทป์ด้วยนะคะพี่รงคะ
                string Includepath = ((MapPath) + filename + Path.GetExtension(FileUpload1.FileName));
                Bitmap originalBMP = new Bitmap(FileUpload1.FileContent);
                // ใส่ขนาดที่นี่
                int newWidth = 200;
                int newHeight = 200;
                Bitmap newBMP = new Bitmap(originalBMP, newWidth, newHeight);
                Graphics oGraphics = Graphics.FromImage(newBMP);
                oGraphics.SmoothingMode = SmoothingMode.AntiAlias; oGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                oGraphics.DrawImage(originalBMP, 0, 0, newWidth, newHeight);
                newBMP.Save(Server.MapPath(MapPath + filename + Path.GetExtension(FileUpload1.FileName)));
                originalBMP.Dispose();
                newBMP.Dispose();
                oGraphics.Dispose();


                SqlConnection scon = new SqlConnection(constr);
                SqlCommand cmd22 = new SqlCommand("UPDATE [Person] set Child_Pic=@FilePath where CID=@Iddek", scon);
                cmd22.Parameters.AddWithValue("@Iddek", Session["CID"]);
                cmd22.Parameters.AddWithValue("@FilePath", Includepath);


                scon.Open();
                cmd22.ExecuteNonQuery();
                scon.Close();


                //xxx คิวรีมาจาก db เอา
                //Image1.ImageUrl = Server.MapPath("xxx");




                //}
                //catch
                //{

                //}
            }
        }








        protected void ImageUpload_2()
        {

            // SqlConnection conn = new SqlConnection(strConnString);
            if (FileUpload3.HasFile)
            {
                //try
                string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
                SqlConnection conn = new SqlConnection(constr);







                //ไปใส่พาธไฟล์เอา

                string MapPath = ("~/pic/cid/");
                string filename = (string)Session["CID"];
                FileUpload3.SaveAs(Server.MapPath(MapPath) + filename + Path.GetExtension(FileUpload3.FileName));
                //FileUploader.SaveAs(filename + ".Jpeg");
                // string SQL = "INSERT INTO [ImageDek] ([Iddek],[FilePath]) VALUES (@Iddek,@Filepath)";
                //เพิ่มไฟล์ไทป์ด้วยนะคะพี่รงคะ
                string Includepath = ((MapPath) + filename + Path.GetExtension(FileUpload3.FileName));
                Bitmap originalBMP = new Bitmap(FileUpload3.FileContent);
                // ใส่ขนาดที่นี่
                int newWidth = 200;
                int newHeight = 200;
                Bitmap newBMP = new Bitmap(originalBMP, newWidth, newHeight);
                Graphics oGraphics = Graphics.FromImage(newBMP);
                oGraphics.SmoothingMode = SmoothingMode.AntiAlias; oGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                oGraphics.DrawImage(originalBMP, 0, 0, newWidth, newHeight);
                newBMP.Save(Server.MapPath(MapPath + filename + Path.GetExtension(FileUpload1.FileName)));
                originalBMP.Dispose();
                newBMP.Dispose();
                oGraphics.Dispose();



                SqlConnection scon = new SqlConnection(constr);
                SqlCommand cmd22 = new SqlCommand("UPDATE [Person] set Child_PicCID=@FilePath where CID=@Iddek", scon);
                cmd22.Parameters.AddWithValue("@Iddek", Session["CID"]);
                cmd22.Parameters.AddWithValue("@FilePath", Includepath);


                scon.Open();
                cmd22.ExecuteNonQuery();
                scon.Close();


                //xxx คิวรีมาจาก db เอา
                //Image1.ImageUrl = Server.MapPath("xxx");




                //}
                //catch
                //{

                //}
            }
        }





        




        protected void updatetb()
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn2 = new SqlConnection(constr);






            SqlCommand CmdSql = new SqlCommand("UPDATE [Person] SET title=@DisabilityType,Title=@Title,DOB=@DOB,Gender=@Gender,BloodType=@BloodType,Nation=@Nation,Race=@Race,Religion=@Religion,Foreigner=@Foreigner,LiveHomeStatus=@LiveHomeStatus,LiveHouseNumber=@LiveHouseNumber,LiveMooNumber=@LiveMooNumber,LiveVillageName=@LiveVillageName,LiveAlley=@LiveAlley,LiveStreetName=@LiveStreetName,LiveTumbon=@LiveTumbon,LiveCity=@LiveCity,LiveProvince=@LiveProvince,LivePostCode=@LivePostCode,LiveMoveInDate=@LiveMoveInDate,LiveMoveOutDate=@LiveMoveOutDate,LiveMoveOutReason=@LiveMoveOutReason,CensusHouseNumber=@CensusHouseNumber,CensusMooNumber=@CensusMooNumber,CensusVillageName=@CensusVillageName,CensusAlley=@CensusAlley,CensusStreetName=@CensusStreetName,CensusTumbon=@CensusTumbon,CensusCity=@CensusCity,CensusProvince=@CensusProvince,CensusPostCode=@CensusPostCode,CensusMoveInDate=@CensusMoveInDate,CensusMoveOutDate=@CensusMoveOutDate,CensusMoveOutReason=@CensusMoveOutReason,HomePhone=@HomePhone,Mobile=@Mobile,RecordedStaffID=@RecordedStaffID,DateTimeUpdate=@DateTimeUpdate WHERE CID=@CID", conn2);
            conn2.Open();

            CmdSql.Parameters.AddWithValue("@DisabilityType", DisabilityType.SelectedValue);
            CmdSql.Parameters.AddWithValue("@Title", TitlesD.SelectedValue);
            CmdSql.Parameters.AddWithValue("@Gender", GenderR.SelectedValue);
            CmdSql.Parameters.AddWithValue("@BloodType", BloodTypeRBL.SelectedValue);
            CmdSql.Parameters.AddWithValue("@DOB", birthday.Text);
            CmdSql.Parameters.AddWithValue("@CID", Session["CID"]);
            CmdSql.Parameters.AddWithValue("@Nation", NationTB.Text);
            CmdSql.Parameters.AddWithValue("@Race", RaceTB.Text);
            CmdSql.Parameters.AddWithValue("@Religion", RaceTB.Text);
            CmdSql.Parameters.AddWithValue("@Foreigner", ForeignD.SelectedValue);
            CmdSql.Parameters.AddWithValue("@LiveHomeStatus", LHomeTB.Text);
            //CmdSql.Parameters.AddWithValue("@EducationStatus", EducationStatus.SelectedValue);
            //บ้านเลขที่
            CmdSql.Parameters.AddWithValue("@LiveHouseNumber", LHomeTB.Text);
            //ชื่อถนน
            CmdSql.Parameters.AddWithValue("@LiveStreetName", LStreetTB.Text);
            CmdSql.Parameters.AddWithValue("@LiveTumbon", LTambonD.SelectedValue);
            CmdSql.Parameters.AddWithValue("@LiveCity", LCityD.SelectedValue);
            CmdSql.Parameters.AddWithValue("@LiveProvince", LProvinceD.SelectedValue);
            CmdSql.Parameters.AddWithValue("@LivePostCode", LPostcodeTB.Text);

            CmdSql.Parameters.AddWithValue("@CensusHouseNumber", CHomeTB.Text);
            CmdSql.Parameters.AddWithValue("@CensusStreetName", CStreetTB.Text);
            CmdSql.Parameters.AddWithValue("@Censustumbon", CTambonD.SelectedValue);
            CmdSql.Parameters.AddWithValue("@CensusCity", CCityD.SelectedValue);
            CmdSql.Parameters.AddWithValue("@CensusProvince", CProvinceD.SelectedValue);
            CmdSql.Parameters.AddWithValue("@CensusPostCode", CPostcodeTB.Text);
            CmdSql.Parameters.AddWithValue("@HomePhone", CTelTB.Text);
            CmdSql.Parameters.AddWithValue("@Mobile", CCellphoneTB.Text);
            CmdSql.Parameters.AddWithValue("@RecordedStaffID", RecordedStaffID.Text);
            CmdSql.Parameters.AddWithValue("@DateTimeUpdate", DateTime.Now);

            CmdSql.Parameters.AddWithValue("@LiveMoveInDate", LMIDTB.Text);
            CmdSql.Parameters.AddWithValue("@LiveMoveOutReason", LiveMoveOutReason.SelectedValue);
            CmdSql.Parameters.AddWithValue("@CensusMoveOutReason", CensusMoveOutReason.SelectedValue);
            CmdSql.Parameters.AddWithValue("@LiveMoveOutDate", LMODTB.Text);


            CmdSql.Parameters.AddWithValue("@CensusMoveOutDate", CMODTB.Text);
            CmdSql.Parameters.AddWithValue("@CensusMoveInDate", CMIDTB.Text);

            CmdSql.Parameters.AddWithValue("@CensusMooNumber", CGroupTB.Text);
            CmdSql.Parameters.AddWithValue("@CensusVillageName", CHomeNTB.Text);
            CmdSql.Parameters.AddWithValue("@CensusAlley", CSoyTB.Text);

            CmdSql.Parameters.AddWithValue("@LiveMooNumber", LGroupTB.Text);
            CmdSql.Parameters.AddWithValue("@LiveVillageName", LHomeNTB.Text);
            CmdSql.Parameters.AddWithValue("@LiveAlley", LSoyTB.Text);

            CmdSql.ExecuteNonQuery();
            conn2.Close();
            //MessageBox("ลงทะเบียนเรียบร้อยครับ");
        }

        protected void Wizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e)
        {
            Response.Redirect("regfamily.aspx");
        }
        //     อัพรูป
     

        protected void Button_picedit_Click(object sender, EventArgs e)
        {
            Panel1.Visible = true;
        }

        protected void uploadpic_Click(object sender, EventArgs e)
        {
            ImageUpload_f();
            ImageUpload_2();
       
            String a;
            a = "reg.aspx?CID=" + Session["CID"] + "";
            Response.Redirect("" + a + "");
        }














        public void loaddatadropdownchildType()
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);

            SqlCommand CmdSql2 = new SqlCommand("SELECT WelfareID,WelfareDescription FROM WelfareCategory", conn);
            conn.Open();

            SqlDataReader reader4 = CmdSql2.ExecuteReader();

            DataTable dt = new DataTable();
            DisabilityType.Items.Clear();
            ListItem newItem = new ListItem();
            newItem.Text = "ประเภทด้อยโอกาส";
            newItem.Value = "0";
            DisabilityType.Items.Add(newItem);

            while (reader4.Read())
            {
                newItem = new ListItem();
                newItem.Text = reader4["WelfareDescription"].ToString();
                newItem.Value = reader4["WelfareID"].ToString();
                DisabilityType.Items.Add(newItem);
            }

        }






        public void loaddatadropdownProvince()
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);

            SqlCommand CmdSql2 = new SqlCommand("SELECT ProvinceID,ProvinceDescription FROM Province", conn);
            conn.Open();

            SqlDataReader reader4 = CmdSql2.ExecuteReader();

            DataTable dt = new DataTable();
            CProvinceD.Items.Clear();
            ListItem newItem = new ListItem();
            newItem.Text = "เลือกจังหวัด";
            newItem.Value = "0";
            CProvinceD.Items.Add(newItem);

            while (reader4.Read())
            {
                newItem = new ListItem();
                newItem.Text = reader4["ProvinceDescription"].ToString();
                newItem.Value = reader4["ProvinceID"].ToString();
                CProvinceD.Items.Add(newItem);
            }

        }

        public void loaddatadropdownProvince2()
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);

            SqlCommand CmdSql2 = new SqlCommand("SELECT ProvinceID,ProvinceDescription FROM Province", conn);
            conn.Open();

            SqlDataReader reader4 = CmdSql2.ExecuteReader();

            DataTable dt = new DataTable();
            LProvinceD.Items.Clear();
            ListItem newItem = new ListItem();
            newItem.Text = "เลือกจังหวัด";
            newItem.Value = "0";
            LProvinceD.Items.Add(newItem);

            while (reader4.Read())
            {
                newItem = new ListItem();
                newItem.Text = reader4["ProvinceDescription"].ToString();
                newItem.Value = reader4["ProvinceID"].ToString();
                LProvinceD.Items.Add(newItem);
            }

        }

        public void loaddatadropdownTitles()
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);

            SqlCommand CmdSql2 = new SqlCommand("SELECT TitleID,Description FROM Title", conn);
            conn.Open();

            SqlDataReader reader4 = CmdSql2.ExecuteReader();

            DataTable dtt = new DataTable();
            TitlesD.Items.Clear();
            ListItem newItem = new ListItem();
           

            while (reader4.Read())
            {
                newItem = new ListItem();
                newItem.Text = reader4["Description"].ToString();
                newItem.Value = reader4["TitleID"].ToString();
                TitlesD.Items.Add(newItem);
            }

        }






        public void loaddataBloodTypeRBL()
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);

            SqlCommand CmdSql2 = new SqlCommand("SELECT BloodTypeID,BloodTypeDescription FROM BloodType", conn);
            conn.Open();

            SqlDataReader reader4 = CmdSql2.ExecuteReader();

            DataTable dtBloodTypeRBL = new DataTable();
            BloodTypeRBL.Items.Clear();
            ListItem newItem = new ListItem();


            while (reader4.Read())
            {
                newItem = new ListItem();
                newItem.Text = reader4["BloodTypeDescription"].ToString();
                newItem.Value = reader4["BloodTypeID"].ToString();
                BloodTypeRBL.Items.Add(newItem);
            }

        }




        public void loaddataGenderR()
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);

            SqlCommand CmdSql2 = new SqlCommand("SELECT GenderCode,GenderThaiDescription FROM [HL7 Gender Standard]", conn);
            conn.Open();

            SqlDataReader reader4 = CmdSql2.ExecuteReader();

            DataTable dtGenderR = new DataTable();
            GenderR.Items.Clear();
            ListItem newItem = new ListItem();


            while (reader4.Read())
            {
                newItem = new ListItem();
                newItem.Text = reader4["GenderThaiDescription"].ToString();
                newItem.Value = reader4["GenderCode"].ToString();
                GenderR.Items.Add(newItem);
            }

        }


        public void loaddataForeignD()
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);

            SqlCommand CmdSql2 = new SqlCommand("SELECT ForeignTypeID,ForeignTypeDescription FROM Foreigner", conn);
            conn.Open();

            SqlDataReader reader4 = CmdSql2.ExecuteReader();

            DataTable dtForeignD = new DataTable();
            ForeignD.Items.Clear();
            ListItem newItem = new ListItem();


            while (reader4.Read())
            {
                newItem = new ListItem();
                newItem.Text = reader4["ForeignTypeDescription"].ToString();
                newItem.Value = reader4["ForeignTypeID"].ToString();
                ForeignD.Items.Add(newItem);
            }

        }


       



        public void loaddatadropdownCCity()
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);

            SqlCommand CmdSql2 = new SqlCommand("SELECT CityID,CityDescription FROM City where ProvinceID=@ProvinceID", conn);
            conn.Open();
            CmdSql2.Parameters.AddWithValue("@ProvinceID", CProvinceD.SelectedValue);

            SqlDataReader reader4 = CmdSql2.ExecuteReader();

            DataTable dtCCityD = new DataTable();
            CCityD.Items.Clear();
            ListItem newItem = new ListItem();
            newItem.Text = "เลือกอำเภอ";
            newItem.Value = "0";
            CCityD.Items.Add(newItem);

            while (reader4.Read())
            {
                newItem = new ListItem();
                newItem.Text = reader4["CityDescription"].ToString();
                newItem.Value = reader4["CityID"].ToString();
                CCityD.Items.Add(newItem);
            }

        }


        public void loaddatadropdownLCity()
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);

            SqlCommand CmdSql2 = new SqlCommand("SELECT CityID,CityDescription FROM City where ProvinceID=@ProvinceID", conn);
            conn.Open();
            CmdSql2.Parameters.AddWithValue("@ProvinceID", LProvinceD.SelectedValue);

            SqlDataReader reader4 = CmdSql2.ExecuteReader();

            DataTable dtLCityD = new DataTable();
            LCityD.Items.Clear();
            ListItem newItem = new ListItem();
            newItem.Text = "เลือกอำเภอ";
            newItem.Value = "0";
            LCityD.Items.Add(newItem);

            while (reader4.Read())
            {
                newItem = new ListItem();
                newItem.Text = reader4["CityDescription"].ToString();
                newItem.Value = reader4["CityID"].ToString();
                LCityD.Items.Add(newItem);
            }

        }





        public void loaddatadropdownCTambon()
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);

            SqlCommand CmdSql2 = new SqlCommand("SELECT TumbonID,TumbonDescription FROM Tumbon where CityID=@CityID", conn);
            conn.Open();
            CmdSql2.Parameters.AddWithValue("@CityID", CCityD.SelectedValue);

            SqlDataReader reader4 = CmdSql2.ExecuteReader();

            DataTable dtCTambon = new DataTable();
            CTambonD.Items.Clear();
            ListItem newItem = new ListItem();
            newItem.Text = "เลือกตำบล";
            newItem.Value = "0";
            CTambonD.Items.Add(newItem);

            while (reader4.Read())
            {
                newItem = new ListItem();
                newItem.Text = reader4["TumbonDescription"].ToString();
                newItem.Value = reader4["TumbonID"].ToString();
                CTambonD.Items.Add(newItem);
            }

        }




        public void loaddatadropdownLTambon()
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);

            SqlCommand CmdSql2 = new SqlCommand("SELECT TumbonID,TumbonDescription FROM Tumbon where CityID=@CityID", conn);
            conn.Open();
            CmdSql2.Parameters.AddWithValue("@CityID", LCityD.SelectedValue);

            SqlDataReader reader4 = CmdSql2.ExecuteReader();

            DataTable dtLTambon = new DataTable();
            LTambonD.Items.Clear();
            ListItem newItem = new ListItem();
            newItem.Text = "เลือกตำบล";
            newItem.Value = "0";
            LTambonD.Items.Add(newItem);

            while (reader4.Read())
            {
                newItem = new ListItem();
                newItem.Text = reader4["TumbonDescription"].ToString();
                newItem.Value = reader4["TumbonID"].ToString();
                LTambonD.Items.Add(newItem);
            }

        }










        protected void CProvinceD_SelectedIndexChanged(object sender, EventArgs e)
        {
            loaddatadropdownCCity();
        }

        protected void CCityD_SelectedIndexChanged(object sender, EventArgs e)
        {
            loaddatadropdownCTambon();
        }

        protected void LProvinceD_SelectedIndexChanged(object sender, EventArgs e)
        {
            loaddatadropdownLCity();
        }

        protected void LCityD_SelectedIndexChanged(object sender, EventArgs e)
        {
            loaddatadropdownCTambon();
        }


        public void loaddatadropdownCityall()
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);

            SqlCommand CmdSql2 = new SqlCommand("SELECT CityID,CityDescription FROM City", conn);
            conn.Open();
          

            SqlDataReader reader4 = CmdSql2.ExecuteReader();

            DataTable dtCCityD = new DataTable();
            CCityD.Items.Clear();
            ListItem newItem = new ListItem();
            newItem.Text = "เลือกอำเภอ";
            newItem.Value = "0";
            CCityD.Items.Add(newItem);

            while (reader4.Read())
            {
                newItem = new ListItem();
                newItem.Text = reader4["CityDescription"].ToString();
                newItem.Value = reader4["CityID"].ToString();
                CCityD.Items.Add(newItem);
            }

        }

        protected void LiveCopyCheck_CheckedChanged(object sender, EventArgs e)
        {
            if (LiveCopyCheck.Checked == true)
            {

                bindtextbox();

            }

            else

            {


                String CensusHousesoys = "";
                LSoyTB.Text = CensusHousesoys;

                String CensusHouseNames = "";
                LHomeNTB.Text = CensusHouseNames;

                String CensusHouseMoos = "";
                LGroupTB.Text = CensusHouseMoos;




                String StreetAddress = "";
                LHomeTB.Text = StreetAddress;
                String StreetName = "";
                LStreetTB.Text = StreetName;

            


                loaddatadropdownLCity();


              

                String Postcode = "";
                LPostcodeTB.Text = Postcode;

                loaddatadropdownLTambon();

                loaddatadropdownProvince2();
                //String inhome = (string)Session["MIDTB"];
                //LMIDTB.Text = inhome;
                //String outhome = (string)Session["MODTB"];
                //LMODTB.Text = outhome;
            
            }
          
        }







        protected void bindtextbox()
        {


            Session["HomeTB"] = CHomeTB.Text;
            Session["GroupTB"] = CGroupTB.Text;
            Session["HomeNTB"] = CHomeNTB.Text;
            Session["SoyTB"] = CSoyTB.Text;
            Session["StreetTB"] = CStreetTB.Text;
   
        
            Session["ProvinceD"] = CProvinceD.SelectedValue;

            Session["CityD"] = CCityD.SelectedValue;
            Session["TambonD"] = CTambonD.SelectedValue;
            Session["PostcodeTB"] = CPostcodeTB.Text;
            Session["MIDTB"] = CMIDTB.Text;
            Session["MODTB"] = CMODTB.Text;





            String CensusHousesoys = (string)Session["SoyTB"];
            LSoyTB.Text = CensusHousesoys;

            String CensusHouseNames = (string)Session["HomeNTB"];
            LHomeNTB.Text = CensusHouseNames;

            String CensusHouseMoos = (string)Session["GroupTB"];
            LGroupTB.Text = CensusHouseMoos;




            String StreetAddress = (string)Session["HomeTB"];
            LHomeTB.Text = StreetAddress;
            String StreetName = (string)Session["StreetTB"];
            LStreetTB.Text = StreetName;

            String Province = (string)Session["ProvinceD"];
            LProvinceD.SelectedValue = Province;


            loaddatadropdownLCity();


            String City = (string)Session["CityD"];
            LCityD.SelectedValue = City;

            String Postcode = (string)Session["PostcodeTB"];
            LPostcodeTB.Text = Postcode;

            loaddatadropdownLTambon();

            String tumbon = (string)Session["TambonD"];
            LTambonD.SelectedValue = tumbon;

            String inhome = (string)Session["MIDTB"];
            LMIDTB.Text = inhome;
            String outhome = (string)Session["MODTB"];
            LMODTB.Text = outhome;

        }




        protected void joinLiveProvince()
        {
             string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);


            SqlCommand CmdSql2 = new SqlCommand("SELECT  Province.[ProvinceDescription] as LiveProvince  FROM [Province] Province join [Person] Person on Person.LiveProvince=Province.ProvinceID  where Person.CID=@CID", conn);
            conn.Open();
            CmdSql2.Parameters.AddWithValue("@CID", Session["CID"]);

            SqlDataReader reader2 = CmdSql2.ExecuteReader();

            if (reader2.Read())
            {
                LProvinceLB.Text = reader2["LiveProvince"].ToString();
            }
            else
            {
                //MessageBox("ไม่พบเลขบัตรครับ");
            }
            conn.Close();
            reader2.Close();


        }



        protected void joinCensusProvince()
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);


            SqlCommand CmdSql2 = new SqlCommand("SELECT  Province.[ProvinceDescription] as CensusProvince  FROM [Province] Province join [Person] Person on Person.CensusProvince=Province.ProvinceID  where Person.CID=@CID", conn);
            conn.Open();
            CmdSql2.Parameters.AddWithValue("@CID", Session["CID"]);

            SqlDataReader reader2 = CmdSql2.ExecuteReader();

            if (reader2.Read())
            {
                CProvinceLB.Text = reader2["CensusProvince"].ToString();
            }
            else
            {
                
            }
            conn.Close();
            reader2.Close();
            
            
        }






        protected void joinCensusCity()
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);


            SqlCommand CmdSql2 = new SqlCommand("SELECT  Province.[CityDescription] as CensusCity  FROM [City] Province join [Person] Person on Person.CensusCity=Province.CityID  where Person.CID=@CID", conn);
            conn.Open();
            CmdSql2.Parameters.AddWithValue("@CID", Session["CID"]);

            SqlDataReader reader2 = CmdSql2.ExecuteReader();

            if (reader2.Read())
            {
                CCityLB.Text = reader2["CensusCity"].ToString();
            }
            else
            {

            }
            conn.Close();
            reader2.Close();


        }

        protected void joinLiveCity()
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);


            SqlCommand CmdSql2 = new SqlCommand("SELECT  Province.[CityDescription] as LiveCity  FROM [City] Province join [Person] Person on Person.LiveCity=Province.CityID  where Person.CID=@CID", conn);
            conn.Open();
            CmdSql2.Parameters.AddWithValue("@CID", Session["CID"]);

            SqlDataReader reader2 = CmdSql2.ExecuteReader();

            if (reader2.Read())
            {
                LCityLB.Text = reader2["LiveCity"].ToString();
            }
            else
            {

            }
            conn.Close();
            reader2.Close();


        }


        //Titles

    }
}